//
//  CShareDelMgr.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/3/10.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "CShareDelMgr.h"
#import "EFengShareDel.h"

@implementation CShareDelMgr


- (BOOL)insertWithShareDel:(EFengShareDel *)shareDel
{
    __block BOOL ret = NO;
    
    
    [[FMShareDataBase shareDataBase].shareQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        ret = [db executeUpdate:@"INSERT INTO EFENGSHAREDEL(shareId, date, type) VALUES (?, ?, ?)",M_STOREVALUE(shareDel.shareId), M_STOREVALUE(shareDel.date),M_STOREVALUE(shareDel.type)];
    }];
    return ret;

}
- (BOOL)batchInsertShareDelWithDelList:(NSArray *)delList
{
    if(delList == nil && [delList count] <= 0)
    {
        return NO;
    }
    //     FMDatabaseQueue *queen = [FMDatabaseQueue  databaseQueueWithPath:[[CFolderMgr shareInstance] companyCommonDatabasePath]];
    __block BOOL ret = NO;
    
    [[FMShareDataBase shareDataBase].shareQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        for(EFengShareDel *share in delList)
        {
            if (!M_ISSTRNULL(share.shareId)) {
                ret = [db executeUpdate:@"INSERT INTO EFENGSHAREDEL(shareId, date, type) VALUES (?, ?, ?)",M_STOREVALUE(share.shareId), M_STOREVALUE(share.date),M_STOREVALUE(share.type)];
                
                if(!ret)
                {
                    *rollback = YES;
                }
                
            }
        }
        
    }];
    return ret;

}

- (NSString *)getMaxDateShareDel
{
    __block NSString *result = nil;
    [[FMShareDataBase shareDataBase].shareQueue inDatabase:^(FMDatabase *db) {
        result = [db stringForQuery:@"select max(date) from EFENGSHAREDEL"];
    }];
    return result;
}

@end
